<template>
	<view>
		<view class="exercise">
			<scroll-view scroll-y="true" class="scroll-box z-padding-32" :show-scrollbar="false" enhanced="true" @scrolltolower="more">
				<view class="z-radius-20 z-margin-b-24 each-item z-flex-c-s-b z-padding-32 z-border-b" v-for="(item,index) in list" wx:key="*this" @tap="video(item)">
					<view class="item-text">
						<view class="z-font-30 title">{{ item.title }}</view>
						<view class="z-margin-t-8 z-font-22 learn-text">
							<view>{{ item.createtime | date('yyyy-mm-dd hh:MM') }}</view>
						</view>
					</view>
					<image :src="cdn(item.image)" class="item-img z-radius-16" mode="aspectFill"></image>
				</view>
				
				<u-empty v-if="finish && list.length === 0" text="暂无培训内容" mode="list"></u-empty>
			</scroll-view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [],
			finish: false,
			loading: false,
			page: 1
		};
	},
	onLoad(options) {
		this.reload();
	},
	methods: {
		video(event) {
			this.util.skip('/service/video/video?url=' + event.videofile + '&name=' + event.title);
		},
		reload() {
			this.list = [],
			this.page = 1,
			this.finish = false
			this.getList();
		},
		more() {
			this.page = ++this.page
			this.getList();
		},
		getList() {
			if (this.finish) {
				return;
			}
			if (this.loading) {
				return;
			}
			this.loading = true
			let data = {
				page: this.page,
				type: 0
			};
			this.http.get('index/trainlist', data)
				.then((res) => {
					if (res.data.length === 0) {
						this.finish = true
					}
					let arr = this.list.concat(res.data);
					this.list = arr
				})
				.finally((res) => {
					this.loading = false
				});
		}
	}
};
</script>

<style>
page {
	background-color: #edf1f4;
}
.exercise {
	height: 100vh;
	/* #ifdef H5 */
	height:calc(100vh - 90rpx);
	/* #endif */
}
.scroll-box {
	height: 100%;
	box-sizing: border-box;
}

.list-box {
	width: 686rpx;
	margin: auto;
}

.title {
	height: 100rpx;
	overflow: hidden;
	display: -webkit-box;
	-webkit-line-clamp: 2; /* 设置最大显示行数 */
	-webkit-box-orient: vertical;
	text-overflow: ellipsis;
}

.item-text {
	width: 363rpx;
	line-height: 48rpx;
}

.item-img {
	width: 200rpx;
	height: 150rpx;
	opacity: 1;
}
.each-item {
	background-color: #fff;
}
.learn-text {
	display: flex;
}
</style>
